package com.asiainfo.hybridapp.application;

import android.Manifest;
import android.app.Application;
import android.content.pm.PackageManager;
import android.support.multidex.MultiDexApplication;
import android.support.v4.app.ActivityCompat;
import android.util.Log;

import com.framework.application.FrameApplication;
import com.framework.utils.Y;
import com.tencent.smtt.sdk.QbSdk;

public class ShareApplication extends MultiDexApplication {

    // //////////////////
    public static ShareApplication share;

    /**
     * 获取ShareApplication的单例
     *
     * @return ApplicationController singleton instance
     */
    public static synchronized ShareApplication getInstance() {
        return share;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        FrameApplication.onCreate(this);
        share = this;
        initX5Environment();
//        CustomProgressDialogUtils.h = new Handler();
        initDefaultUncaughtExceptionHandler();

        Y.y("ShareApplication:" + "initMyLocation1");
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            //			initLocation_gaode();
            Y.y("initLocation_gaode");
        }
    }

    private void initX5Environment() {
        QbSdk.initX5Environment(getApplicationContext(), new QbSdk.PreInitCallback() {
            @Override
            public void onCoreInitFinished() {
                Log.e("yy", "onCoreInitFinished");
            }

            @Override
            public void onViewInitFinished(boolean b) {
                Log.e("yy", "onViewInitFinished:" + b);
            }
        });
    }

    /**
     * 初始化全局未被捕获的异常
     */
    private void initDefaultUncaughtExceptionHandler() {
        // 设置该MyUncaughtExceptionHandler为程序的默认处理器
        MyUncaughtExceptionHandler myUncaughtExceptionHandler = new MyUncaughtExceptionHandler(
                this);
        Thread.setDefaultUncaughtExceptionHandler(myUncaughtExceptionHandler);
    }
}
